package onjava.generics;

// generics/GenericHolder.java
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.

/**
 * 
 * 简单泛型
 *
 * @author Lucky Yang
 */
public class GenericHolder<T> {
  private T a;

  public GenericHolder() {
  }

  public void set(T a) {
    this.a = a;
  }

  public T get() {
    return a;
  }

  public static void main(String[] args) {
    GenericHolder<Automobile> h3 = new GenericHolder<Automobile>();
    // type checked
    h3.set(new Automobile());
    // No cast needed
    Automobile a = h3.get();
    System.out.println(a);
    // - h3.set("Not an Automobile"); // Error
    // - h3.set(1); // Error
  }
}
